package com.sukaiyi.giteeideaplugin.search.codesegments;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.sukaiyi.giteeideaplugin.model.CodeSegmentNode;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@State(name = "GiteePluginForIdea.CodeSegment", storages = {@com.intellij.openapi.components.Storage(value = "$APP_CONFIG$/GiteePluginForIdea.CodeSegment.xml")})
public class CodeSegmentData implements PersistentStateComponent<CodeSegmentData> {

    @Getter
    @Setter
    private CodeSegmentNode root;

    @Nullable
    @Override
    public CodeSegmentData getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull CodeSegmentData pluginSetting) {
        XmlSerializerUtil.copyBean(pluginSetting, this);
    }

    public static CodeSegmentData getInstance() {
        return ServiceManager.getService(CodeSegmentData.class);
    }
}
